package org.lc.eic.messaging.assembly;

import java.sql.Timestamp;
import java.util.UUID;

import org.lc.eic.api.requestreply.exception.RequestProcessingException;
import org.lc.eic.messgeconstruct.requestreply.Reply;
import org.lc.eic.messgeconstruct.requestreply.Request;

public class EnvelopeWrapRequestDispatcher<I, O> implements
		org.lc.eic.api.requestreply.sync.RequestDispatcher<I, O> {
	
	private org.lc.eic.api.requestreply.sync.RequestDispatcher<Request<I>, Reply<O>> requestDispatcher;

	public O request(I requestInput) throws RequestProcessingException {
		Request<I> request = new Request<I>();
		
		request.setContent(requestInput);
		request.setContentType(requestInput.getClass().getName());
		
		request.setTimestamp(new Timestamp(System.currentTimeMillis()));
		request.setExpiration(new Timestamp(Long.MAX_VALUE));
		request.setUniqueID(UUID.randomUUID().toString());
		
		
		
		Reply<O> reply = requestDispatcher.request(request); 
		return reply.getContent();
	}

	public void setRequestDispatcher(
			org.lc.eic.api.requestreply.sync.RequestDispatcher<Request<I>, Reply<O>> requestDispatcher) {
		this.requestDispatcher = requestDispatcher;
	}
	
	
}
